//
//  SCEmoticonModel.swift
//  weibo
//
//  Created by 阿城 on 15/12/15.
//  Copyright © 2015年 阿城. All rights reserved.
//

import UIKit

class SCEmoticonModel: NSObject, NSCoding {

    var chs: String?
    var cht: String?
    var gif: String?
    var png: String?
    var code: String?
    var type: String?
    var isEmoji: Bool {
        return type! == "1"
    }
    var path: String?
    var belong: String?
    
    convenience init(dict: [String: AnyObject]) {
        self.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
    override init() {
        super.init()
    }
    
    required init?(coder aDecoder: NSCoder) {
        chs = aDecoder.decodeObjectForKey("chs") as? String
        png = aDecoder.decodeObjectForKey("png") as? String
        type = aDecoder.decodeObjectForKey("type") as? String
        code = aDecoder.decodeObjectForKey("code") as? String
        belong = aDecoder.decodeObjectForKey("belong") as? String
        //计算属性  每次的bundle都不一样
        //path = aDecoder.decodeObjectForKey("path") as? String

    }
    
    func encodeWithCoder(aCoder: NSCoder) {
        aCoder.encodeObject(chs, forKey: "chs")
        aCoder.encodeObject(png, forKey: "png")
        aCoder.encodeObject(type, forKey: "type")
        aCoder.encodeObject(code, forKey: "code")
        aCoder.encodeObject(belong, forKey: "belong")
        //aCoder.encodeObject(path, forKey: "path")
        
    }
    
    override func isEqual(object: AnyObject?) -> Bool {
        if let other = object as? SCEmoticonModel{
            
            if other.chs == chs || other.png == png{
                return true
            }
            
        }
       return super.isEqual(object)
    }
    
}
